package com.digitalxpert.jargle.TestGui;
import java.awt.event.FocusEvent;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Formatter;
import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatter;
public class SelectableFormattedField extends JFormattedTextField {
	boolean inFocus;
	public SelectableFormattedField(NumberFormat format) {
		super(format);
	}
	public SelectableFormattedField(DefaultFormatter formatter) {
		super(formatter);
	}
	protected void processFocusEvent(FocusEvent e) {
		super.processFocusEvent(e);
		if (e.getID() == FocusEvent.FOCUS_GAINED) {
			System.out.println("focuseed");
			if (inFocus) {
				selectAll();
			} else {
				inFocus = true;
			}
		}
		if (e.getID() == FocusEvent.FOCUS_LOST) {
			System.out.println(getSelectedText());
			if (getSelectedText() != null) {
				System.out.println("bla");
				
			} else {
				inFocus = false;
			}
			System.out.println(getText());
//			try {
//				AbstractFormatter formatter = getFormatter();
//				if (formatter != null) {
//					formatter.stringToValue(this.getText());
//				}
//			} catch (ParseException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//			}
		}
	}
}
